package com.cyj.springtx1anno.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyj.springtx1anno.entity.User;
import com.cyj.springtx1anno.mapper.IUserMapper;
import com.cyj.springtx1anno.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @description:
 * @Author C_Y_J
 * @create 2021-03-05 09:44
 **/
@Service
@Transactional(isolation = Isolation.DEFAULT)
public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements IUserService {
    @Autowired
    private IUserMapper userMapper;

    @Override
        @Transactional(isolation = Isolation.DEFAULT)
    public void transfer() {
        //李四向张三转账500

        //update user set money= money-500 where user_name = '李四'
        UpdateWrapper<User> updateWrapper1 = new UpdateWrapper<User>().eq("user_name", "李四").set("money", "4500");
        userMapper.update(null, updateWrapper1);
        int i = 1 / 0;
        //update user set money= money+500 where user_name = '张三'
        UpdateWrapper<User> updateWrapper2 = new UpdateWrapper<User>().eq("user_name", "张三").set("money", "4500");
        userMapper.update(null, updateWrapper2);

    }
}
